package com.survey.demo.ui.activity;

import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyConfig;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.widget.layout.WrapRecyclerView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.survey.demo.R;
import com.survey.demo.aop.SingleClick;
import com.survey.demo.app.AppActivity;
import com.survey.demo.http.bean.AddressBean;
import com.survey.demo.http.bean.StaffEntity;
import com.survey.demo.http.glide.GlideApp;
import com.survey.demo.http.model.HttpData;
import com.survey.demo.http.request.LoginApi;
import com.survey.demo.http.response.LoginBean;
import com.survey.demo.ui.fragment.MeFragment;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/10/18
 *    desc   : 地址管理界面
 */
public final class AddressListActivity extends AppActivity implements OnRefreshLoadMoreListener {
    private SmartRefreshLayout mRefreshLayout;
    private WrapRecyclerView mRecyclerView;
    private  BaseQuickAdapter adapter;
    private RelativeLayout rl_add_address;
    private List<AddressBean> list = new ArrayList<AddressBean>();
    @Override
    protected int getLayoutId() {
        return R.layout.address_list_activity;
    }

    @Override
    protected void initView() {
        mRefreshLayout = findViewById(R.id.rl_status_refresh);
        mRecyclerView = findViewById(R.id.addr_recycle);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        rl_add_address = findViewById(R.id.rl_add_address);
        adapter =new BaseQuickAdapter<AddressBean, BaseViewHolder>(R.layout.item_address_manage, list) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, AddressBean bean) {
                TextView name =  (TextView)baseViewHolder.getView(R.id.tv_name);
                TextView phone =  (TextView)baseViewHolder.getView(R.id.tv_phone);
                TextView addr =  (TextView)baseViewHolder.getView(R.id.tv_address);
                name.setText(bean.getName());
                phone.setText(bean.getPhone());
                addr.setText(bean.getDefaultAddr());
                baseViewHolder.getView(R.id.edit_addr).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(InsertAddrActivity.class);
                    }
                });
                baseViewHolder.getView(R.id.del_addr).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
            }
        };
        mRecyclerView.setAdapter(adapter);
        mRefreshLayout.setOnRefreshLoadMoreListener(this);
        setOnClickListener(rl_add_address);
    }

    @Override
    protected void initData() {
        for(int i=0;i<3;i++){
            AddressBean addressBean = new AddressBean();
            addressBean.setName("张三");
            addressBean.setPhone("150****1561");
            addressBean.setDefaultAddr("黑龙江省长春市让路胡同二环东路大厦B*3A");
            list.add(addressBean);
        }
        adapter.setNewData(list);
    }

    @SingleClick
    @Override
    public void onClick(View view) {
          startActivity(InsertAddrActivity.class);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        mRefreshLayout.finishLoadMore();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        mRefreshLayout.finishRefresh();
    }
}